package com.jinke.uang.view;

import android.app.Dialog;
import android.content.Context;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.ViewGroup;

import com.jinke.uang.R;
import com.jinke.uang.interfaces.ILoading;

import androidx.annotation.Nullable;

//todo 环形进度条
public class TipsDialog extends Dialog implements ILoading {
    public TipsDialog(Context context) {
        super(context);
        initViews(context);
    }

    public TipsDialog(Context context, int themeResId) {
        super(context, themeResId);
        initViews(context);
    }

    protected TipsDialog(Context context, boolean cancelable,
                         @Nullable OnCancelListener cancelListener) {
        super(context, cancelable, cancelListener);
        initViews(context);
    }

    private void initViews(Context context) {
        ViewGroup rootView =
                (ViewGroup) LayoutInflater.from(context).inflate(R.layout.layout_of_tips_dialog,
                        null);
        setContentView(rootView);
//        setCancelable(false);
        setCanceledOnTouchOutside(false);
    }

    //设置点击外部环形进度条是否可以消失，true默认可消失
    public void setCanceledEnable(boolean enable) {
        setCanceledOnTouchOutside(enable);
    }


    @Override
    public void showLoading() {
        show();
    }

    @Override
    public void dismissLoading() {
        dismiss();
    }

    //物理返回键不可点击
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            return false;
        } else {
            return super.onKeyDown(keyCode, event);
        }
    }

}
